pp108 : Working with Dispatch Algorithm

Working with Dispatch Algorithm

This topic describes the procedure to create and configure a Custom Dispatch Algorithm for a task.

While designing a business process, you model the tasks to be sent to targets such as work lists, teams, roles, or users. But at the runtime due to various factors, such as workload balancing, changes in priorities, expertise and so on, you may want to re-route these tasks to other targets. Process Platform enables you to dynamically re-route the task to other targets, as per the requirement, with the help of intelligent work dispatching algorithms. You must do the following to create the Dispatch Algorithm and use it:

  • Implement the Custom Dispatch Logic in a Java class
  • Create the Custom Dispatch Algorithm document and provide the details of the Java class
  • Configure the Business Process Model to use this dispatch algorithm
  • Publish the dispatch algorithm contents to make them available at the runtime
  • Register the dispatch algorithm with the Notification Service Container

The following procedure describes creating the dispatch algorithm:

  1. To Implement the Custom Dispatch Algorithm, specify the required logic in a Java class that implements the com.cordys.notification.customdispatch.CustomTaskDispatcher interface provided by Process Platform, in the notification.jar found at <Process_Platform_install_dir>/components/notification, as shown below:
    public interface CustomTaskDispatcher {
     
    	/** * Implement the custom dispatch logic in this method.
        	* @param taskInformation An instance of <code>TaskInformation</code>
        	* @return returns a list of <code>IAssignment</code> instances.
        	* The notification would be dispatched to all the assignments in this list.*/ 
    	public Collection<IAssignment> getAssignments(TaskInformation taskInformation);
    	/* implement your logic to decide on task dispatch */
    }

    TaskInformation holds the task details. Refer to CustomTaskDispatcher and TaskInformation in the Java APIs for more information on implementing the Custom Dispatch Algorithm and the usage of TaskInformation APIs.

  2. Create a Java archive of the Custom Dispatch Algorithm. Refer to Creating a Java Archive Definition for the procedure to create a JAR file.
  3. To create the Dispatch Algorithm document that contains the reference to the Java class, do the following:
    1. Select a starting point and click to open the Dispatch Algorithm modeler. The Dispatch Algorithm properties page appears.
    2. Enter the name and description of the Dispatch Algorithm, to identify the Custom Dispatch Algorithm, in the Name and Description text boxes respectively.
    3. Type the complete path for the class that implements the Custom Dispatch Algorithm in the Fully Qualified Class Name field.
    4. Click on the toolbar. The Custom Dispatch Algorithm is saved and displayed in the Workspace Documents (Explorer) under the specified project.
  4. To use this dispatch algorithm in a business process, select the created Dispatch Algorithm from the drop-down list from Human Task activity property sheet of the business process.
  5. Right-click the project and select Publish to Organization to make the dispatch algorithm contents to be available at the runtime.
  6. To Register the Custom Dispatch Algorithm, add the JAR file to the classpath of the Notification Service Container. Refer the JRE section of the Service Container Configuration Interface for more information. The Dispatch Algorithm is registered with the Notification Service.
  • The Dispatch Algorithm is created and configured to be used at the runtime. When the business process is executed, the tasks are routed as per the logic provided in the dispatch algorithm. However, if the conditions provided in the dispatch algorithm are not met, then the default work assignment specified for the human task is applied.
  • The Dispatch Algorithm is used to resolve the target only while creating a task, and the task is sent to the resolved target.

Example

The following example code demonstrates the implementation of a Java Class using CustomTaskDispatcher and how to specify the custom dispatch logic in the method getAssignments.

Pre-requisite: notification.jar must be in the CLASSPATH to compile the given sample java code.

package com.cordys.notification.customdispatch;
 
import java.util.ArrayList;
import java.util.Collection;
import com.cordys.notification.customdispatch.CustomTaskDispatcher;
import com.cordys.notification.customdispatch.TaskInformation;
import com.cordys.notification.internal.task.Assignment;
import com.cordys.notification.task.AssignmentType;
import com.cordys.notification.task.IAssignment;
 
public class MyCustomTaskDispatcher implements CustomTaskDispatcher
{
	public Collection<IAssignment> getAssignments(TaskInformation taskInformation)
	{
		// Write your logic here to decide on the target.
		String userDN = "cn=testuser,cn=organizational users,o=system,cn=cordys,cn=w212,o=vanenburg.com";
		String RoleDN = "cn=testrole,cn=organizational roles,o=system,cn=cordys,cn=w212,o=vanenburg.com";
		String TeamID = "001CC438-8F47-11E2-EB11-FC2D603E9626";
		String WorklistID = "001CC438-8F47-11E2-EB12-013A4A739626";
 
		// Create Assignment object based on the target. Targets could be either a User, Role, Team, or a Work list.
		// If the target is a role or a user, provide the corresponding DN as the parameter.
		// If the target is a Team or a Work list then provide the ID of the team or work list as the parameter.
 
		IAssignment assignmentUser = new Assignment(userDN, AssignmentType.user);
		IAssignment assignmentRole = new Assignment(RoleDN, AssignmentType.role);
		IAssignment assignmentTeam = new Assignment(TeamID, AssignmentType.team);
		IAssignment assignmentWorklist = new Assignment(WorklistID, AssignmentType.worklist);
 
		ArrayList<IAssignment> assignments = new ArrayList<IAssignment>();
		// Either of these the assignment objects or any combination of these assignment objects can be added to the returned assignments collection. 		
		assignments.add(assignmentUser);
		assignments.add(assignmentRole);
		assignments.add(assignmentWorklist);
 
		/*** UseCase # If any of the current target types is 'team', then only add the 'team Assignment' to the Assignments ***/
		Collection<IAssignment> CurrentTargets = taskInformation.getAssignments();
		Iterator<IAssignment> oIterator = CurrentTargets.iterator();
		while(oIterator.hasNext())
		{
			IAssignment assignment1 = oIterator.next();
			if(assignment1.getType() == AssignmentType.team)
			{
				assignments.add(assignmentTeam);
			}
			break;
		}
		return assignments;
	}
}